/*
 * @Author: zi.yang
 * @Date: 2021-10-02 15:12:32
 * @LastEditors: zi.yang
 * @LastEditTime: 2021-10-03 17:07:10
 * @Description: In User Settings Edit
 * @FilePath: \ziYangPM\src\router\permission.js
 */

import store from '@/store'

import router from './index'

// 路由鉴权
router.beforeEach((to, from, next) => {
  const NoInterception = ['/auth/sign-in1', '/auth/sign-up1', '/dark/auth/sign-in1', '/dark/auth/sign-up1']
  // 不拦截 login 页面
  if (NoInterception.includes(to.path)) {
    store.commit('User/DEL_TOKEN')
    store.commit('User/DEL_USER_INFO')
  }
  const authRequired = !NoInterception.includes(to.path)
  const { token } = store.state.User
  if (authRequired && (token === null || token === '')) {
    return next('/auth/sign-in1')
  }
  next()
})
